<template>
	<view>
		<view class="container">
			<view class="m-hairline--bottom foot-line"></view>
			<image class="m-backdrop" src="../../static/icon/icon_back2.png" mode="widthFix"></image>
			<view class="p30">
				<swiper class="course-swiper" autoplay circular>
					<swiper-item v-for="(item,index) in bannerLists" :key="item.id" @click="bannerNav(item.minapp_url)"><image class="img-swiper" :src="item.thumb_image" mode="aspectFill"></image></swiper-item>
				</swiper>
			</view>
			<!--  -->
			<view class="course-tab flex-box pb10">
				<view v-for="(item, index) in courseTabList" :class="{ active: courseTabCurrent === index }" @click="courseTabClick(index)" class="tab-item mr5 flex-1">{{ item }}</view>
			</view>
			<!--  -->
			<view class="plr30 ptb10">
				<block v-if="courseTabCurrent == 0">
					<view class="course-list2">
						<navigator :url="'/pages/course_video_detail/course_video_detail?course_id='+item.course.id" class="nav-course flex-box ptb30" hover-class="none" v-for="(item,index) in courseLists">
							<!-- <view class="time-long">00:08:00</view> -->
							<image class="img-course mr20" :src="item.course.thumb_image" mode="aspectFill"></image>
							<view class="flex-1">
								<view class="m-ellipsis fs26 col-0 mb10">{{item.course.name}}</view>
								<view class="m-ellipsis fs22 col-6 mb30">{{item.course.description}}</view>
								<view class="flex-box">
									<image class="icon1 mr10" v-if="item.course.type==1" src="/static/icon/icon_tv.png" mode="aspectFit"></image>
									<image class="icon1 mr10" v-if="item.course.type==2" src="/static/icon/icon_video.png" mode="aspectFit"></image>
									<image class="icon1 mr10" v-if="item.course.type==3" src="/static/icon/icon_book.png" mode="aspectFit"></image>
									<view class="flex-1 fs22 col-9">{{item.course.type==3?item.course.total_num:item.course.play_count}}人学习过</view>
									<!-- ios端会屏蔽支付价格，如果需要开启请把v:if注释掉 -->
									<template v-if="!isIos  || platformStatus==1">
									<view class="fs20 col-yellow fwb" v-if="item.course.is_charge == 0">免费</view>
									<view class="g-price1 fwb" v-else>{{item.course.salesprice}}</view>
									</template>
								</view>
							</view>
						</navigator>
						<view class="g-btn3-wrap">
							<view class="g-btn3" :class="{nomore: courseListsMore.nomore == true || courseListsMore.loading == true}" @click="fetchCourse">{{courseListsMore.text}}</view>
						</view>
					</view>
				</block>
				<block v-else-if="courseTabCurrent == 1">
					<view class="offline_course">
						<navigator class="item mb40" :url="'/pages/offline_course_detail/offline_course_detail?course_id='+item.course_id" v-for="(item,index) in offlineCourseLists" hover-class="none">
							<view class="img-box pr mb25">
								<image :src="item.course_image" mode="aspectFill"></image>
								<view class="tc fs20 col-f" :class="(item.state==1 || item.state==2)? 'status1' : 'status2'">{{item.state_text}}</view>
							</view>
							<view class="mb25 fs28 col-black fwb m-ellipsis">{{item.course_name}}</view>
							<view class="flex-box mb25">
								<view class="g-price1 flex-1 fwb">{{item.course_salesprice}}</view>
								<image class="icon1 mr10" src="/static/icon/icon_already.png" mode="aspectFit"></image>
								<view class="fs22 col-9" v-if="item.offline_course">已报名{{item.offline_course.enroll_count}}人 | 剩余{{item.offline_course.total_count}}人</view>
							</view>
							<view class="flex-box mb25">
								<image class="icon1 mr20" src="/static/icon/icon_time1.png" mode="aspectFit"></image>
								<view class="fs26 col-3 flex-1">开课时间：{{item.course_start_time_text}} 至 {{item.course_end_time_text}}</view>
							</view>
							<view class="flex-box">
								<image class="icon1 mr20" src="/static/icon/icon_location.png" mode="aspectFit"></image>
								<view class="fs26 col-3 flex-1">开课地点：{{item.course_address}}</view>
							</view>
						</navigator>
						<view class="g-btn3-wrap">
							<view class="g-btn3" :class="{nomore: offlineCourseListsMore.nomore == true || offlineCourseListsMore.loading == true}" @click="fetchOfflineCourse">{{offlineCourseListsMore.text}}</view>
						</view>
					</view>
				</block>
				<block v-else-if="courseTabCurrent == 2">
					<view class="course-list2">
							<navigator :url="'/pages/course_video_detail/course_video_detail?course_id='+item.course.id" class="nav-course flex-box ptb30" hover-class="none" v-for="(item,index) in collectLists">
								<!-- <view class="time-long">00:08:00</view> -->
								<image class="img-course mr20" :src="item.course.thumb_image" mode="aspectFill"></image>
								<view class="flex-1">
									<view class="m-ellipsis fs26 col-0 mb10">{{item.course.name}}</view>
									<view class="m-ellipsis fs22 col-6 mb30">{{item.course.description}}</view>
									<view class="flex-box">
										<image class="icon1 mr10" v-if="item.course.type==1" src="/static/icon/icon_tv.png" mode="aspectFit"></image>
										<image class="icon1 mr10" v-if="item.course.type==2" src="/static/icon/icon_video.png" mode="aspectFit"></image>
										<image class="icon1 mr10" v-if="item.course.type==3" src="/static/icon/icon_book.png" mode="aspectFit"></image>
										<view class="flex-1 fs22 col-9">{{item.course.type==3?item.course.total_num:item.course.play_count}}人学习过</view>
										<!-- ios端会屏蔽支付价格，如果需要开启请把v:if注释掉 -->
										<template v-if="!isIos  || platformStatus==1">
										<view class="fs20 col-yellow fwb" v-if="item.course.is_charge == 0">免费</view>
										<view class="g-price1 fwb" v-else>{{item.course.salesprice}}</view>
										</template>
									</view>
								</view>
							</navigator>
							<view class="g-btn3-wrap">
								<view class="g-btn3" :class="{nomore: collectListsMore.nomore == true || collectListsMore.loading == true}" @click="fetchCollectCourse">{{collectListsMore.text}}</view>
							</view>
						</view>
					
					
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	const util = require('@/xiluedu/util.js');
export default {
	data() {
		return {
			bannerLists:[],
			courseTabList: ['线上课程', '线下课程', '我的收藏'],
			courseTabCurrent: 0,
			
			courseLists:[],
			courseListsMore: {page:1},
			
			offlineCourseLists: [],
			offlineCourseListsMore: {page:1},
			
			collectLists:[],
			collectListsMore: {page:1,text:'正在加载...'},
			platformStatus: getApp().globalData.platformStatus,
			isIos: getApp().globalData.isIos,
		};
	},
	onLoad(){
		this.fetchBanners();
		if(this.$user.getUserinfo(true)){
			this.fetchCourse();
			this.fetchOfflineCourse();
			this.fetchCollectCourse();
		}
	},
	onPullDownRefresh(){
		this.refresh();
		setTimeout(function () {
			uni.stopPullDownRefresh();
		}, 1000);
	},
	methods: {
		bannerNav(url){
			if(url){
				uni.navigateTo({
					url: url
				})
			}
		},
		refresh(){
			this.courseLists = [];
			this.courseListsMore = {page:1};
			
			this.offlineCourseLists = [];
			this.offlineCourseListsMore = {page:1};
			
			this.collectLists = [];
			this.collectListsMore = {page:1,text:'正在加载...'};
			this.fetchCourse();
			this.fetchOfflineCourse();
			this.fetchCollectCourse();
		},
		
		fetchBanners(){
			this.$core.get({url:'xiluedu.banner/banners',data:{group:'course_class'},success:(ret)=>{
			    this.bannerLists = ret.data;
			}});
		},
		//线上
		fetchCourse() {
		    util.fetch(this, 'xiluedu.user/course_lists', {pagesize:10}, 'courseListsMore', 'courseLists', 'data', list=>{
		    });
		},
		//线下
		fetchOfflineCourse() {
		    util.fetch(this, 'xiluedu.offline_order/offline_orders', {pagesize:10}, 'offlineCourseListsMore', 'offlineCourseLists', 'data', list=>{
		    });
		},
		//收藏
		fetchCollectCourse() {
		    util.fetch(this, 'xiluedu.user/course_collection', {pagesize:10}, 'collectListsMore', 'collectLists', 'data', list=>{
		    });
		},
		
		// 点击详情tab
		courseTabClick(i) {
			this.courseTabCurrent = i;
			
		}
	}
};
</script>

<style scoped>
.container {
	overflow-y: unset;
}
/*  */
.course-swiper {
	width: 690rpx;
	height: 285rpx;
}
.course-swiper .img-swiper {
	display: block;
	width: 690rpx;
	height: 285rpx;
	border-radius: 10rpx;
}
/*  */
.course-tab {
	position: sticky;
	top: 0;
	left: 0;
	right: 0;
	background-color: #fff;
	z-index: 10;
}
.course-tab .tab-item {
	position: relative;
	line-height: 65rpx;
	text-align: center;
	font-size: 28rpx;
	font-weight: 500;
	color: #000000;
}
.course-tab .tab-item::after {
	position: absolute;
	right: 0;
	top: 50%;
	transform: translateY(-50%);
	content: '';
	width: 1rpx;
	height: 35rpx;
	background: #e1e1e1;
}
.course-tab .tab-item.active {
	color: var(--red);
}
.course-tab .tab-item.active:before {
	position: absolute;
	bottom: 0;
	left: 50%;
	transform: translateX(-50%);
	content: '';
	width: 123rpx;
	height: 4rpx;
	background: var(--red);
}
/*  */
.course-list2 .img-course {
	display: block;
	width: 280rpx;
	height: 160rpx;
	border-radius: 10rpx;
}
.course-list2 .nav-course + .nav-course {
	border-top: 1rpx solid var(--border);
}
/*  */

.offline_course {
	background-color: #fff;
	border-radius: 10rpx 10rpx 0 0;
}
.offline_course .item {
	width: 690rpx;
}
.offline_course .img-box {
	width: 690rpx;
	height: 360rpx;
	border-radius: 10rpx;
	overflow: hidden;
}
.offline_course .img-box image {
	display: block;
	width: 690rpx;
	height: 360rpx;
	border-radius: 10rpx;
}
.offline_course .img-box .status1 {
	position: absolute;
	top: 0;
	left: 0;
	width: 76rpx;
	height: 34rpx;
	border-radius: 10rpx 0 0 0;
	line-height: 34rpx;
	background: linear-gradient(90deg, #d7aa4e, #f4c972);
}
.offline_course .img-box .status2 {
	position: absolute;
	top: 0;
	left: 0;
	width: 76rpx;
	height: 34rpx;
	border-radius: 10rpx 0 0 0;
	line-height: 34rpx;
	background: #d8d8d8;
}
.offline_course .icon1 {
	display: block;
	width: 30rpx;
	height: 30rpx;
}
</style>
